<template>
    <h2>增加优惠券</h2>
    <input type="button" value="优惠券展示" @click="tiaoyouhq">
    <table class="table table-bordered">
        <tr>
            <td>优惠券类型</td>
            <td>
                <select v-model="prist.tyid">
                    <option value="">请选择</option>
                    <option :value="item.dtid" v-for="item in type">{{ item.dtname }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>优惠券标题</td>
            <td>
                <input type="text" v-model="prist.title">
            </td>
        </tr>
        <tr>
            <td>优惠券颜色</td>
            <td>
                <input type="color" v-model="prist.cocol">
            </td>
        </tr>
        <tr>
            <td>优惠券数量</td>
            <td>
                <input type="number" v-model="prist.number">
            </td>
        </tr>
        <tr>
            <td>优惠券限领人数</td>
            <td>
                <input type="number" v-model="prist.peopnum">
            </td>
        </tr>
        <tr>
            <td>优惠券使用条件</td>
            <td>
                <input type="number" v-model="prist.tjcon">
            </td>
        </tr>
        <tr>
            <td>优惠券减免金额</td>
            <td>
                <input type="number" v-model="prist.jmoney">
            </td>
        </tr>
        <tr>
            <td>优惠券折扣</td>
            <td>
                <input type="text" v-model="prist.zkmoney">
            </td>
        </tr>
        <tr>
            <td>优惠券使用开始时间</td>
            <td>
                <input type="date" v-model="prist.sdate">
            </td>
        </tr>
        <tr>
            <td>优惠券使用结束时间</td>
            <td>
                <input type="date" v-model="prist.edate">
            </td>
        </tr>
        <tr>
            <td>优惠券适用门店</td>
            <td>
                <select v-model="prist.stoirid">
                    <option value="">请选择</option>
                    <option :value="it.sid" v-for="it in store">{{ it.sname }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>备注</td>
            <td>
                <textarea cols="30" rows="3" v-model="prist.desc"></textarea>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="添加" @click="addddddsss">
            </td>
        </tr>
    </table>
  </template>
  
  <script setup lang="ts">
  import {onMounted, reactive, toRefs} from 'vue'
  import axios from 'axios'
  import {useRouter,useRoute} from 'vue-router'

  const router=useRouter()
  const route=useRoute()

  let data:any=reactive({
    type:[],
    store:[],
    prist:{
        tyid:'',
        title:'',
        cocol:'',
        number:'',
        peopnum:'',
        tjcon:'',
        jmoney:'',
        zkmoney:'',
        sdate:'',
        edate:'',
        stoirid:'',
        desc:''
    }
  })
  let {type,store,prist} =toRefs(data)

  onMounted(()=>{
    gettype()
    getstore()
  })

  const gettype=()=>{
    axios({
        url:'/api/Mem/Bindtype',
        method:'get'
    })
    .then(res=>{
        type.value=res.data.data;
    })
  }

  const getstore=()=>{
    axios({
        url:'/api/Mem/Bindstore',
        method:'get'
    })
    .then(res=>{
        store.value=res.data.data;
    })
  }

  const addddddsss=()=>{
    let obj={
        "typeid": prist.value.tyid,
  "dtitle": prist.value.title,
  "color": prist.value.cocol,
  "number": prist.value.number,
  "pepnum": prist.value.peopnum,
  "contj": prist.value.tjcon,
  "jmoney": prist.value.jmoney,
  "zkmoney": prist.value.zkmoney,
  "starttime": prist.value.sdate,
  "endtime": prist.value.edate,
  "storeid": prist.value.stoirid,
  "desc": prist.value.desc,
  "dstates": 1,
  "isdele": false
    }
    axios({
        url:'/api/Mem/Adddis',
        method:'post',
        data:obj
    })
    .then(res=>{
        if(res.data.data==1){
            alert("添加优惠券成功")
        }else if(res.data.data==-2){
            alert("优惠券名称不能重复")
        }else{
            alert("添加优惠券失败")
        }
    })
  }

  const tiaoyouhq=()=>{
    router.push('showdis')
  }
  </script>
  
  <style scoped>
  
  </style>